package com.jn.okhttp.views;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.jn.okhttp.R;
import com.jn.okhttp.base.BaseActivity;
import com.jn.okhttp.contract.TestContract;
import com.jn.okhttp.presenter.TestPresenter;

public class TestActivity extends BaseActivity
        implements TestContract.ITestView, View.OnClickListener {

    private TestContract.ITestPresenter mPresenter;
    private Button mButtonGet;
    private Button mButtonPost;
    private EditText mEdit;
    private TextView mText;

    @Override
    public int getLayoutId() {
        return R.layout.activity_test;
    }

    @Override
    public void init() {
        mPresenter = new TestPresenter(this, this);
        mButtonGet = findViewById(R.id.button_get);
        mButtonPost = findViewById(R.id.button_post);
        mEdit = findViewById(R.id.edit);
        mText = findViewById(R.id.text);
        mButtonGet.setOnClickListener(this);
        mButtonPost.setOnClickListener(this);
    }

    @Override
    public void showData(String data) {
        mText.setText(data);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        String keyWord = mEdit.getText().toString();
        if (id == R.id.button_get) {
            //if (!TextUtils.isEmpty(keyWord)) {
            mPresenter.get(keyWord);
            //}
        } else if (id == R.id.button_post) {
            //if (!TextUtils.isEmpty(keyWord)) {
            mPresenter.post(keyWord);
            //}
        }
    }
}